﻿namespace WMS6.Web
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Web;
    using WMS6.Web.TaskMgtServiceRef;

    public class TaskMgtServiceClientProxy : BasePage
    {
        public string DeleteTaskDetail(List<string> taskDetailID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            TaskMgtServiceClient client = new TaskMgtServiceClient("WSHttpBinding_ITaskMgtService");
            try
            {
                result = client.DeleteTaskDetail(taskDetailID, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string DeleteTaskManagerUser(List<string> userID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            TaskMgtServiceClient client = new TaskMgtServiceClient("WSHttpBinding_ITaskMgtService");
            try
            {
                result = client.DeleteTaskManagerUser(userID, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string DeleteTaskManagerUserDetail(string userID, List<string> lineID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            TaskMgtServiceClient client = new TaskMgtServiceClient("WSHttpBinding_ITaskMgtService");
            try
            {
                result = client.DeleteTaskManagerUserDetail(userID, lineID, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public DataSet GetAllTaskDetail()
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            DataSet ds = null;
            TaskMgtServiceClient client = new TaskMgtServiceClient("WSHttpBinding_ITaskMgtService");
            try
            {
                ds = client.GetAllTaskDetail(pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return ds;
        }

        public DataSet GetAllTaskManagerUser()
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            DataSet ds = null;
            TaskMgtServiceClient client = new TaskMgtServiceClient("WSHttpBinding_ITaskMgtService");
            try
            {
                ds = client.GetAllTaskManagerUser(pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return ds;
        }

        public static TaskMgtServiceClientProxy GetInstance()
        {
            return new TaskMgtServiceClientProxy();
        }

        public TaskDetailInfo GetTaskDetailByID(string taskdetailID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            TaskDetailInfo taskDetailInfo = null;
            TaskMgtServiceClient client = new TaskMgtServiceClient("WSHttpBinding_ITaskMgtService");
            try
            {
                taskDetailInfo = client.GetTaskDetailByID(taskdetailID, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return taskDetailInfo;
        }

        public DataSet GetTaskDetailByQueryList(TaskDetailQueryEntity taskdetailQuery)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            DataSet ds = null;
            TaskMgtServiceClient client = new TaskMgtServiceClient("WSHttpBinding_ITaskMgtService");
            try
            {
                ds = client.GetTaskDetailByQueryList(taskdetailQuery, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return ds;
        }

        public TaskManagerUserInfo GetTaskManagerUserByID(string userID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            TaskManagerUserInfo taskManagerUserInfo = null;
            TaskMgtServiceClient client = new TaskMgtServiceClient("WSHttpBinding_ITaskMgtService");
            try
            {
                taskManagerUserInfo = client.GetTaskManagerUserByID(userID, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return taskManagerUserInfo;
        }

        public DataSet GetTaskManagerUserByQueryList(TaskManagerUserQueryEntity taskManagerUserQueryEntity)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            DataSet ds = null;
            TaskMgtServiceClient client = new TaskMgtServiceClient("WSHttpBinding_ITaskMgtService");
            try
            {
                ds = client.GetTaskManagerUserByQueryList(taskManagerUserQueryEntity, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return ds;
        }

        public TaskManagerUserDetailInfo GetTaskManagerUserDetailByID(string userID, string lineID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            TaskManagerUserDetailInfo taskManagerUserDetailInfo = null;
            TaskMgtServiceClient client = new TaskMgtServiceClient("WSHttpBinding_ITaskMgtService");
            try
            {
                taskManagerUserDetailInfo = client.GetTaskManagerUserDetailByID(userID, lineID, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return taskManagerUserDetailInfo;
        }

        private PubParasInfo InitPubParasInfo()
        {
            if (base.UserInfo != null)
            {
                return new PubParasInfo { UserID = base.UserInfo.UserID, UserLanguage = base.UserInfo.Preference.Lang, CurrentWH = base.UserInfo.CurrentWH };
            }
            HttpContext.Current.Response.Redirect("../Login.aspx?from=Logout", true);
            return null;
        }

        public string InsertTaskDetail(TaskDetailInfo taskDetailInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            TaskMgtServiceClient client = new TaskMgtServiceClient("WSHttpBinding_ITaskMgtService");
            try
            {
                result = client.InsertTaskDetail(taskDetailInfo, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string InsertTaskManagerUser(TaskManagerUserInfo taskManagerUserInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            TaskMgtServiceClient client = new TaskMgtServiceClient("WSHttpBinding_ITaskMgtService");
            try
            {
                result = client.InsertTaskManagerUser(taskManagerUserInfo, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string InsertTaskManagerUserDetail(TaskManagerUserDetailInfo taskManagerUserDetailInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            TaskMgtServiceClient client = new TaskMgtServiceClient("WSHttpBinding_ITaskMgtService");
            try
            {
                result = client.InsertTaskManagerUserDetail(taskManagerUserDetailInfo, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string UpdateTaskDetail(TaskDetailInfo taskDetailInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            TaskMgtServiceClient client = new TaskMgtServiceClient("WSHttpBinding_ITaskMgtService");
            try
            {
                result = client.UpdateTaskDetail(taskDetailInfo, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string UpdateTaskManagerUser(TaskManagerUserInfo taskManagerUserInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            TaskMgtServiceClient client = new TaskMgtServiceClient("WSHttpBinding_ITaskMgtService");
            try
            {
                result = client.UpdateTaskManagerUser(taskManagerUserInfo, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string UpdateTaskManagerUserDetail(TaskManagerUserDetailInfo taskManagerUserDetailInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            TaskMgtServiceClient client = new TaskMgtServiceClient("WSHttpBinding_ITaskMgtService");
            try
            {
                result = client.UpdateTaskManagerUserDetail(taskManagerUserDetailInfo, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }
    }
}

